# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : zsj.py
# @Time     : 2024/4/21 22:16
# @Author   : Robot-Zsj
"""
description:

i:
2 2
1 0
1 1

o:
3
"""

n, m = map(int, input().split())

matrix = [list(map(int, input().split())) for _ in range(n)]

offsets = ((-1, 0), (1, 0), (0, -1), (0, 1))


def bfs(i, j):
    count = 1
    matrix[i][j] = 0

    queue = [[i, j]]

    while len(queue) > 0:
        x, y = queue.pop(0)

        for offsetX, offsetY in offsets:
            newX = x + offsetX
            newY = y + offsetY

            if n > newX >= 0 and m > newY >= 0 and matrix[newX][newY] == 1:
                count += 1
                matrix[newX][newY] = 0
                queue.append([newX, newY])

    return count


def getResult():
    ans = 0

    for i in range(n):
        for j in range(m):
            if matrix[i][j] == 1:
                ans = max(ans, bfs(i, j))
    return ans


print(getResult())
